$(function () {


    initTable();
});

/**
 * 初始化表格
 */
function initTable() {
    $('#appTable').DataTable({
        language: Language,
        columns: [
            {
                "data": "name",
                "title": "名称"
            },
            {
                "data": "enable",
                "title": "状态",
                "render": function (data, type, row, meta) {
                    if (data) {
                        return "已启用"
                    } else {
                        return "已禁用"
                    }
                }
            },
            {
                "data": "createTime",
                "title": "创建时间"
            },
            {
                "data": "updateTime",
                "title": "修改时间"
            },
            {
                "data": "null",
                "title": "操作",
                "render": function (data, type, row, meta) {
                    return `<button class="btn btn-danger" style="margin-right: 5px" onClick="remove('${row.id}')">删除</button>` +
                        `<button class="btn btn-primary" data-toggle="modal" data-target="#updateModal" onClick="modifyShow(this)">修改</button>`
                }
            }
        ],
        dom: 'rt<"bottom"ilp><"clear">',
        destroy: true,
        searching: false,
        processing: true,
        serverSide: true,
        bSort: false,
        lengthMenu: [10],
        autoWidth: false,


        ajax: {
            type: "post",
            contentType: "application/json",
            headers: getHeaders(),
            url: searchUrl,
            dataFilter: dataFilterFunc,
            data: function (param) {
                let json = $("#appForm").serializeObject()
                json.type = 0;
                json.pageNum = param.start / 10 + 1;
                json.pageSize = param.length;
                json.orderByKey = "id"
                return JSON.stringify(json)
            },
            error: errorFunc
        }
    });
}

/**
 * 查询
 */
function search() {
    reloadTable('appTable');
}

/**
 * 重置
 */
function reset() {
    clearForm();

    search();
}

/**
 * 清空表单
 */
function clearForm() {
    resetForm("appForm")
}

function modifyShow(_this) {
    let tr = $(_this).parent().parent();
    let row = getRowDataTable('appTable', tr);
    loadForm("updateForm", row)
}


